home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
FILER
/
ECHO.ZIP
/
!Echo
/
c
/
echo
Wrap
Text File
|
1996-01-19
|
8KB
|
344 lines
/* echo.c */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "wimpt.h"
#include "res.h"
#include "msgs.h"
#include "template.h"
#include "baricon.h"
#include "event.h"
#include "dbox.h"
#include "menu.h"
#include "wimp.h"
#include "os.h"
#include "werr.h"
#include "win.h"
#include "tracker.h"
#include "xfersend.h"
#include "help.h"
#define echo__FOK 0 /* OK action button */
#define echo__FName 2 /* name field */
#define echo__FIcon 3 /* icon to drag. */
static char echo__srcname[256];
static int echo__filetype;
static xfersend_saveproc echo__saveproc;
static xfersend_sendproc echo__sendproc;
static xfersend_printproc echo__printproc;
static void *echo__savehandle;
static int echo__estsize = 0;
static char *echo__filename;
static dbox echo__d;
static void echo__click(wimp_i i)
{ i = i;
}
static void echo__info(void)
{ dbox inf;
if (inf = dbox_new("progInfo"), !inf)
werr(FALSE, msgs_lookup("main2"));
dbox_setfield(inf, 3, "1.00 (29 Apr 94)");
dbox_show(inf);
dbox_fillin(inf);
dbox_dispose(&inf);
}
static void echo__menuhandler(void *handle, char *hit)
{ handle = handle;
switch (hit[0])
{ case 1:
if (hit[1]) echo__info();
break;
case 2:
exit(0);
break;
}
}
void echo__setname(wimp_w w, wimp_i ii, char *name)
{
wimp_icreate i;
wimp_i iii;
i.w = w;
wimpt_noerr(wimp_get_icon_info(i.w, ii, &i.i));
wimpt_noerr(wimp_delete_icon(w, ii));
i.i.flags &= ~wimp_ITEXT; /* set not text */
i.i.flags |= wimp_ISPRITE + wimp_INDIRECT; /* set sprite */
strcpy(i.i.data.indirectsprite.name, name);
if (wimp_spriteop(24, i.i.data.indirectsprite.name))
sprintf(i.i.data.indirectsprite.name, "application");
i.i.data.indirectsprite.spritearea = (void *) 1;
wimpt_noerr(wimp_create_icon(&i, &iii));
}
static BOOL echo__saveevents(dbox d, void *ev, void *handle)
{
wimp_eventstr *e = (wimp_eventstr*) ev;
if (help_dboxrawevents(d, ev, "SAVEAS")) return TRUE; /* handle interactive help */
switch (e->e)
{ case wimp_EBUT:
if (e->data.but.m.bbits == wimp_BDRAGLEFT)
{
dbox_getfield(d, echo__FName, echo__filename, 256);
xfersend(echo__filetype, echo__filename, echo__estsize,
echo__saveproc, echo__sendproc,
echo__printproc, e, handle);
return TRUE;
}
}
return FALSE;
}
BOOL echo__saveas(int filetype, char *name, int estsize,
xfersend_saveproc saveproc,
xfersend_sendproc sendproc,
xfersend_printproc printproc,
void *handle, char *spr)
{ if (echo__d) return FALSE;
if (!echo__filename) echo__filename = malloc(256);
echo__d = dbox_new("xfer_send");
if (echo__d == 0) return FALSE;
echo__filetype = filetype;
echo__saveproc = saveproc;
echo__sendproc = sendproc;
echo__printproc = printproc;
echo__savehandle = handle;
echo__estsize = estsize;
dbox_show(echo__d);
xfersend_close_on_xfer(TRUE, dbox_syshandle(echo__d));
echo__setname((wimp_w) dbox_syshandle(echo__d), echo__FIcon, spr);
dbox_raw_eventhandler(echo__d, echo__saveevents, echo__savehandle);
dbox_setfield(echo__d, echo__FName, name);
strncpy(echo__filename, name, 256);
while (dbox_fillin(echo__d) == echo__FOK)
{
int i;
BOOL dot;
dbox_getfield(echo__d, echo__FName, echo__filename, 256);
for (i = 0, dot = FALSE; !dot && echo__filename[i]; )
dot = echo__filename[i++] == '.';
if (!dot)
{ werr(FALSE, msgs_lookup("saveas1:To save, drag the icon to a directory display."));
continue;
}
xfersend_set_fileissafe(TRUE);
if (echo__saveproc(echo__filename, echo__savehandle) == TRUE && !dbox_persist())
break;
}
xfersend_close_on_xfer(FALSE, 0);
xfersend_clear_unknowns();
dbox_hide(echo__d);
dbox_dispose(&echo__d);
echo__d = 0;
return TRUE;
}
/* If the specified file exists in the app copy it from
* <echo$dir>.link.name substituting the application
* name into it
*/
static BOOL echo__copy(char *name, char *app, char *als, BOOL cond)
{ os_filestr fcb;
char in[256], out[256];
char path[256];
FILE *inf, *outf;
int c;
char *lp, *np;
strcpy(path, app);
for (lp = np = path; *np; np++)
if (*np == '.' || *np == ':')
lp = np;
if (lp != path) *lp = '\0';
if (cond)
{ sprintf(in, "%s.%s", app, name);
fcb.action = 17;
fcb.name = in;
if (wimpt_complain(os_file(&fcb)))
return FALSE;
if (fcb.action == 0)
return TRUE; /* OK, just don't copy it */
}
sprintf(in, "<Echo$Dir>.Link.%s", name);
if (wimpt_complain(os_file(&fcb)))
return FALSE;
if (fcb.action == 0)
return TRUE; /* OK, just don't copy it */
sprintf(out, "%s.%s", als, name);
if (inf = fopen(in, "r"), !inf)
goto fail;
if (outf = fopen(out, "w"), !outf)
goto fail1;
c = getc(inf);
while (c != EOF)
{ if (c == '?')
fprintf(outf, "%s", app);
else if (c == '@')
fprintf(outf, "%s", path);
else
putc(c, outf);
c = getc(inf);
}
fclose(inf);
fclose(outf);
fcb.action = 1;
fcb.name = out;
if (wimpt_complain(os_file(&fcb))) return FALSE;
return TRUE;
fail1:
fclose(inf);
fail:
werr(FALSE, msgs_lookup("main7"), name);
return FALSE;
}
static BOOL echo__saver(char *name, void *handle)
{ os_filestr fcb;
fcb.action = 17;
fcb.name = name;
if (!os_file(&fcb) && fcb.action != 0)
{ werr(FALSE, msgs_lookup("main6"), name);
return FALSE;
}
fcb.action = 8;
fcb.name = name;
if (wimpt_complain(os_file(&fcb))) return FALSE;
if (!echo__copy("!Boot", echo__srcname, name, TRUE) ||
!echo__copy("!Run", echo__srcname, name, TRUE) ||
!echo__copy("!Original", echo__srcname, name, FALSE))
return FALSE;
return TRUE;
}
static BOOL echo__sender(void *handle, int *maxbuf)
{
handle = handle;
maxbuf = maxbuf;
werr(FALSE, msgs_lookup("main4"));
return FALSE;
}
static int echo__printer(char *name, void *handle)
{
name = name;
handle = handle;
werr(FALSE, msgs_lookup("main4"));
return xfersend_printFailed;
}
static void echo__process(char *name, int type)
{ char *lp, *np;
if (type != 0x2000)
{ werr(FALSE, msgs_lookup("main3"));
return;
}
strcpy(echo__srcname, name);
for (np = name, lp = name; *np; np++)
if (*np == '.' || *np == ':')
lp = np + 1;
echo__saveas(0x2000, lp, 1,
echo__saver,
echo__sender,
echo__printer,
NULL, lp);
}
static void echo__iconproc(wimp_eventstr *e, void *handle)
{
switch (e->e)
{ case wimp_ESEND:
case wimp_ESENDWANTACK:
switch (e->data.msg.hdr.action)
{ case wimp_MDATALOAD:
echo__process(e->data.msg.data.dataload.name,
e->data.msg.data.dataload.type);
break;
}
break;
}
}
int main()
{
wimpt_init("Echo");
res_init("Echo");
msgs_init();
template_init();
baricon("!echo", 1, echo__click);
win_register_event_handler(win_ICONBARLOAD, echo__iconproc, NULL);
event_attachmenu(win_ICONBAR,
menu_new("Echo", msgs_lookup("main1:>Info,Quit")),
echo__menuhandler, NULL);
for (;;)
event_process();
return 0;
}